﻿#include "Sound.h"


Sound::Sound()
{
	_sound = NULL;
}

Sound &Sound::operator = (Sound idsound)
{
	_sound = idsound._sound;

	return *this;
}

int Sound::Init_DirectSound(HWND hWnd)
{
	HRESULT result;

	_sound = new CSoundManager();

	result = _sound->Initialize(hWnd, DSSCL_PRIORITY);
	if (result != DS_OK)
		return 0;

	//thiết lập primary buffer
	result = _sound->SetPrimaryBufferFormat(2, 22050, 16);
	if (result != DS_OK)
		return 0;

	return 1;
}

CSound *Sound::LoadSound(LPTSTR  ifileName)
{
	HRESULT result;
	CSound *iwave;

	result = _sound->Create(&iwave, ifileName);
	if (result != DS_OK)
		return NULL;

	return iwave;
}

void Sound::PlaySound(CSound *isound)
{
	isound->Play();
}

void Sound::LoopSound(CSound *isound)
{
	isound->Play(0, DSBPLAY_LOOPING);
}

void Sound::StopSound(CSound *isound)
{
	isound->Stop();
}


Sound::~Sound()
{
}
